package listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

//添加监听器注解
//由MyListener类实现ServletContext、HttpSession、ServletRequest三类对象创建、销毁事件的监听
@WebListener
public class MyListener implements ServletContextListener, HttpSessionListener, ServletRequestListener {
	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		System.out.println("ServletContext对象被创建了");
	}

	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		System.out.println("servletContext对象被销毁了");
	}

	@Override
	public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
		System.out.println("servletRequest对象被销毁了");
	}

	@Override
	public void requestInitialized(ServletRequestEvent servletRequestEvent) {
		System.out.println("servletRequest对象被创建了");
	}

	@Override
	public void sessionCreated(HttpSessionEvent httpSessionEvent) {
		System.out.println(" HttpSession对象被创建了");
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
		System.out.println(" HttpSession对象被销毁了");
	}

}
